"use strict";
const aggregate = require('yi-aggregate');

module.exports = {
    description:'根据路由分组获取API接口',
    handler(req, res, next) {
        let pipeObjectArray=[
            [
                {$match:req.query.filter},
                    {$sort: {app: 1, route: 1}},
                    {
                        $group: {
                            _id: {route: "$route"},
                            items: {$addToSet: {_id: "$_id",open:"$open",security :"$security", description:"$description",extend:"$extend" }}
                        }
                    },
                    {$project:{_id:0,route:"$_id.route",items:"$items"}}],
            []
        ];
            aggregate.pageAggregate(req.mongo,'api',pipeObjectArray,req.page,null,(e,r)=>{
            if (e)return res.err.mongoError(e);
            res.reply(r);
        })

    }
};
